<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 80px;
      }
    </style>
  </head>
  <body>
    <div class="box" style="width: 100px">占剑这个牛逼</div>
    <script>
      window.onload = function () {
        let box = document.querySelector(".box");
        //打印也拿不到，因为只能拿到行内样式，行外样式拿不到
        console.log(box.style);
        // 设置样式
        box.style.width = "200px";
        box.style.height = "100px";
        box.style.textAlign = "center";
        box.style.lineHeight = "100px";
        box.style.backgroundColor = "red";
      };
    </script>
  </body>
</html>
